package com.car.loan.framework.aspectj.impl;

import com.car.loan.common.enums.LoanStatusEnum;
import com.car.loan.common.utils.StringUtils;
import com.car.loan.framework.aspectj.DataStatusSqlService;
import com.car.loan.project.xr.util.bo.business.LoanBaseInfo;
import com.car.loan.project.xr.util.enums.BusinessApostilleStatus;
import com.car.loan.project.xr.util.enums.CarInfoStatus;
import com.car.loan.project.xr.util.enums.ContractAuditStatus;
import com.car.loan.project.xr.util.enums.FileAuditStatus;
import com.car.loan.project.xr.util.enums.LicenseInfoStatus;
import com.car.loan.project.xr.util.enums.LoanBusinessAuditStatus;
import com.car.loan.project.xr.util.enums.MortgageInfoStatus;
import org.springframework.stereotype.Service;

/**
 * @author huangding
 * @description 业务状态
 * @date 2019/11/9 16:07
 */
@Service
public class MortgageInfoStatusSqlServiceImpl implements DataStatusSqlService {

    @Override
    public LoanStatusEnum getLoanStatusEnum() {
        return LoanStatusEnum.MORTGAGE_INFO_STATUS;
    }

    @Override
    public LoanBaseInfo getStatusRemark(LoanBaseInfo loanBaseInfo) {
        Long mortgageInfoStatus = loanBaseInfo.getMortgageInfoStatus();
        String statusRemark = StringUtils.EMPTY;
        if (MortgageInfoStatus.INIT.status == mortgageInfoStatus) {
            statusRemark = "待录入";
        } else if (MortgageInfoStatus.SUBMIT.status == mortgageInfoStatus) {
            statusRemark = "已录入";
        }
        loanBaseInfo.setStatusRemark(statusRemark);
        return loanBaseInfo;
    }

    @Override
    public String getSql(String statusAlias, Integer status) {
        String sql = "{}.file_audit_status = " + FileAuditStatus.INIT.status
            + " and ({}.business_audit_status = "
            + LoanBusinessAuditStatus.PASS.status + " or {}.business_apostille_status ="
            + BusinessApostilleStatus.PASS.status
            + ") and {}.license_info_status = "
            + LicenseInfoStatus.SUBMIT.status;
        if (status != null) {
            sql += " and {}.mortgage_info_status =  " + status;
        }
        return sql.replace("{}", statusAlias);
    }

    @Override
    public String getSortSql(String statusAlias) {
        return " order by {}.license_info_time desc".replace("{}", statusAlias);
    }
}
